package com.applet.user.controller;

import com.applet.common.annotation.Anonymous;
import com.applet.common.annotation.Log;
import com.applet.common.core.controller.BaseController;
import com.applet.common.core.domain.AjaxResult;
import com.applet.common.core.page.TableDataInfo;
import com.applet.common.enums.BusinessType;
import com.applet.common.utils.poi.ExcelUtil;
import com.applet.user.domain.Publish;
import com.applet.user.domain.dto.PublishDto;
import com.applet.user.service.IPublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 兼职发布Controller
 * 
 * @author ruoyi
 * @date 2024-08-16
 */
@Api(tags = "兼职发布")
@RestController
@RequestMapping("/user/publish")
public class PublishController extends BaseController
{
    @Autowired
    private IPublishService publishService;

    /**
     * 查询兼职发布列表
     */
//    @PreAuthorize("@ss.hasPermi('user:publish:list')")
    @ApiOperation(value = "查询兼职发布列表")
    @GetMapping("/list")
    public TableDataInfo list(PublishDto publishDto)
    {
        startPage();
        List<Publish> list = publishService.selectPublishList(publishDto);
        return getDataTable(list);
    }
    /**
     * 统计兼职数据
     */
    @ApiOperation(value = "统计兼职数据")
    @GetMapping("/statistics")
    public AjaxResult partTimeStatistics()
    {
        return success(publishService.selectPartTimeStatistics());
    }

    /**
     * 统计前五兼职
     */
    @ApiOperation(value = "统计被申请次数前五兼职")
    @GetMapping("/top")
    public AjaxResult statisticsTopFive()
    {
        return success(publishService.selectStatisticsTopFive());
    }

    /**
     * 根据用户id查询兼职发布列表
     */
    @ApiOperation(value = "根据用户id查询兼职发布列表")
    @GetMapping("/userId")
    public TableDataInfo selectPublishByUserId()
    {
        startPage();
        List<Publish> list = publishService.selectPublishByUserId();
        return getDataTable(list);
    }

    /**
     * 导出兼职发布列表
     */
//    @PreAuthorize("@ss.hasPermi('common:publish:export')")
    @Log(title = "兼职发布", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出兼职发布列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PublishDto publishDto)
    {
        List<Publish> list = publishService.selectPublishList(publishDto);
        ExcelUtil<Publish> util = new ExcelUtil<Publish>(Publish.class);
        util.exportExcel(response, list, "兼职发布数据");
    }

    /**
     * 获取兼职发布详细信息
     */
//    @PreAuthorize("@ss.hasPermi('user:publish:query')")
    @ApiOperation(value = "获取兼职发布详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(publishService.selectPublishById(id));
    }

    /**
     * 新增兼职发布
     */
//    @PreAuthorize("@ss.hasPermi('common:publish:add')")
    @Log(title = "兼职发布", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增兼职")
    @PostMapping
    public AjaxResult add(@RequestBody Publish publish)
    {

        return toAjax(publishService.insertPublish(publish));
    }

    /**
     * 修改兼职发布
     */
//    @PreAuthorize("@ss.hasPermi('user:publish:edit')")
    @Log(title = "修改兼职", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改兼职发布信息")
    @PutMapping
    public AjaxResult edit(@RequestBody Publish publish)
    {
        return toAjax(publishService.updatePublish(publish));
    }

    /**
     * 删除兼职发布
     */
//    @PreAuthorize("@ss.hasPermi('user:publish:remove')")
    @Log(title = "兼职发布", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除兼职发布")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(publishService.deletePublishByIds(ids));
    }
}
